import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
  // 项目名称-此处对文件[ index.html ]引用路径有影像
  base: "./",
  build: {
    // 打包文件夹名称
    outDir: "smart-port/l1",
    // 静态资源目录名称
    assetsDir: "assets",
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes("/node_modules/")) {
            // 设置需要独立打包的npm包
            const expansions = [
              "axios",
              "echarts",
              "lodash",
              "xgis-ol",
              "vue-router",
            ]; 
            const c = expansions.find((exp) =>
              id.includes(`/node_modules/${exp}`)
            );
            if (c) {
              return `${c}-exp`;
            } else {
              return "vendor";
            }
          }
        },
      },
    },
  },
  publicPath: "/",
  server: {
    // 开发环境打开端口
    port: 8430,
    proxy: {
      "/api": {
        target: "http://172.18.10.194",
        changeOrigin: true,
      },
      "/3D/": {
        target: "http://172.18.10.104",
        changeOrigin: true,
        startswidth: "/3D",
      },
      "/iserver": {
        target: "http://172.18.10.104:8090",
        changeOrigin: true,
        startswidth: "/iserver",
      },
      "/cimp-platform-webapi": {
        target: "http://172.18.10.222:8088",
        changeOrigin: true,
        startswidth: "/iserver",
      },
    },
  },
});
